<template>
	<view class="index">
		<view class="index_nav" @click.stop="onjianche">
			<!-- 额度选择导航栏 -->
			<view class="q_nav">
				<!-- <view class="n_back" @click="navigateBack">
				  <image src="../../static/p_back.png" mode=""></image>
				</view> -->
				<!-- <navigator open-type="exit" target="miniProgram">退出</navigator> -->
				<view class="launchapp" @click.stop="navigateBack">
					<image src="../../static/p_back.png" mode=""></image>
				</view>

				<text class="nav_title">Loan Details</text>
				<view class="n_kefu" @click.stop="ClickcustomerService">
					<image src="../../static/p_kefu.png" mode=""></image>
				</view>
			</view>
			<view class="index_header">
				<view class="loadingBox">
					<view class="loaning"> {{loaning}} </view>
				</view>
				<view class="loan_txt">
					<text class="loan_title">Loanable Amount</text>
					<text class="loan_mony">₹{{ amount }}</text>
					<view class="loan_aline"> </view>
					<view class="loan_button">
						<span @click.stop="RouterClick('Loan agreement')">Loan agreement</span>
						<span class="loan_alines"></span>
						<span @click.stop="RouterClick('Loan details')">Loan details</span>
					</view>
				</view>
			</view>
			<view class="swiperbox">
				<swiper class="swiper" :disable-touch="true" circular :indicator-dots="false" :autoplay="true"
					:interval="2000" :duration="500" :vertical="true">
					<swiper-item class="swiperItem" v-for="(itm, idx) in swipers" :key="idx">{{ itm }}</swiper-item>
				</swiper>
			</view>

			<view class="index_min">
				<view class="min_center" v-if="currentData.headline && currentData.updated && currentData.content
          ">
					<view class="m_loan">{{ currentData.headline }}
						<image class="m_loanImage" src="../../static/gth.png" mode=""></image>
					</view>
					<view class="min_steps">
						<u-steps direction="column">
							<u-steps-item :title="currentData.headline + ' ' + currentData.updated"
								:desc="currentData.content">
								<view class="slot-icon" slot="icon" inactiveIcon="checkmark"><u-icon name="checkmark"
										color="#fff" size="28"></u-icon></view>
							</u-steps-item>
						</u-steps>
					</view>
				</view>
				<view class="min_center" v-else>
					<text class="m_loan">Loan approved</text>
					<view class="min_steps">
						<u-steps :current="1" direction="column">
							<u-steps-item title="Loan approved"
								desc="Your loan application has been submitted please contact customer service for final review">
								<view class="slot-icons" slot="icon" inactiveIcon="checkmark"><u-icon name="checkmark"
										color="#fff" size="28"></u-icon></view>
							</u-steps-item>
							<u-steps-item title="Submit loan order"
								desc="Your loan order has been submitted,please wait">
								<view class="slot-icon" slot="icon" inactiveIcon="checkmark"><u-icon name="checkmark"
										color="#fff" size="28"></u-icon></view>
							</u-steps-item>
						</u-steps>
					</view>
				</view>
			</view>
		</view>
		<button class="SERVICE" @click.stop="ClickcustomerService">
			<image src="../../static/p_kefu.png" mode=""></image>CUSTOMER SERVICE
		</button>
		<view class="buttontext">
			<image class="buttonimg" src="../../static/gth.png" mode=""></image>Please contact customer service to
			withdraw the
			amount
		</view>
		<view class="cu-bar tabbar bg-white shadow foot" style="height: 182rpx">
			<view :class="PageCur == 'home' ? 'action text-red' : 'action text-gray'" @click="NavChange"
				data-cur="home">
				<view class="cuIcon-homefill"></view>Home
			</view>
			<view :class="PageCur == 'mine' ? 'action text-red' : 'action text-gray'" @click="NavChange"
				data-cur="mine">
				<view class="cuIcon-peoplelist"></view>Me
			</view>
		</view>
		<uni-popup ref="popupRef" type="center" position="center" :show="isPopupPay" class="popupRef">
			<view class="popup">
				<view class="popupTitle">
					<view class="TitleText">{{orderData.description}}</view>
					<view class="popupIcon" @click="popupCancel">x</view>
				</view>
				<view class="popupMain">
					<view class="popupText">{{orderData.paydescription}}</view>
				</view>
				<view class="popupBtn">
					<view class="btntext cancel" @click="popupCancel">Cancel</view>
					<view class="btntext pay" @click="popupPay">Pay</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="popup10" type="center" :mask-click="false">
			<view class="returns">
				<view class="pop-text"> A new Customer Service Manager has been assigned to you！ </view>
				<view class="pop-btn">
					<button @click="sures" class="quit">Confirm</button>
					<button @click="closesurepop" class="closes">Close</button>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="popup11" type="center" :mask-click="false">
			<view class="returns">
				<view class="pop-text"> A new Customer Service Manager has been assigned to you！ </view>
				<view class="pop-btn">
					<button @click="fenpei11" class="quit">Confirm</button>
					<button @click="closeopen11" class="closes">Close</button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import $_storage from "../../common/util/storage";
	import {
		getEncryptString,
		getDecryptString
	} from "../../defaut";
	import {
		msglist
	} from "../../common/util/common";
	import {
		debounce
	} from "@/common/util/debounce.js";
	export default {
		data() {
			// const authentication4 = $_storage.getStorage("authentication_4");
			return {
				PageCur: "home",
				commponent1Key: 0,
				commponent2Key: 0,
				swipers: [],
				isPopupPay: true,
				currentData: {
					content: "",
					headline: "",
					updated: "",
				},
				submitData: {
					payUrl: "",
				},
				amount: 0,
				orderData: {
					description: "",
					paydescription: "",
					payStatus: "",
				},
				current: 0,
				popupTime: 0,
				loaning: 'loaning',
				isStartTime: false,
				kutel: '',
				kuna: '',
				kename: '',
				kefutel: '',
				banben: '',
				ishuxing: '',
				jiance: false, //客服检测
				nativePlug: null, //打点
				popshow: false,
				timer: null,
				dingdan: '', //订单信息
				timeskefu: '', //首页客服检测时间
				bgtel:'', //变更手机号
				bgname:''
			};
		},
		onLoad: function(val) {
			this.getUserInfo("click");
			this.PageCur = "home";
			++this.commponent1Key;
			++this.commponent2Key;
			this.ishuxing = val;
		},
		onShow() {
			uni.setStorageSync('currentPage', '/pages/index/index'); // 保存当前页面到本地存储
			this.jiance = uni.getStorageSync("jiance");
			this.getSystemInfo();
			this.ondingdan();
			// 刚进入页面会有一次客服检测
			this.onjianche();
			// if (uni.getStorageSync("huxing")) {
			// 	return;
			// } else {
			// 	// this.onlpop(uni.getStorageSync("dingtime"));
			// }

			 console.log('1111',uni.getStorageSync("kename"))
		},
		methods: {
			NavChange: function(e) {
				this.PageCur = e.currentTarget.dataset.cur;
				const pages = getCurrentPages();
				const currentPage = pages[pages.length - 1];
				const routes = {
					"pages/mine/mine": 'mine',
					"pages/index/index": 'home',
				}
				if (routes[currentPage.route] == this.PageCur) return

				if (e.currentTarget.dataset.cur == "mine") {
					uni.setStorageSync("jiance", false);
					this.$Router.replaceAll({
						name: "mine",
					});
				} else if (e.currentTarget.dataset.cur == "home") {
					this.$Router.replaceAll({
						name: "index",
					});
				}
			},
			// 返回
			navigateBack() {
				// #ifdef H5
				// uni.removeStorageSync("token");
				// uni.navigateTo({
				//   url: "/pages/login/login",
				// });
				// uni.removeStorageSync("token");
				// this.$Router.replace({ name: 'login' })
				// #endif

				// #ifdef APP-PLUS
				// uni.removeStorageSync("token");
				if (plus.os.name.toLowerCase() === "android") {
					plus.runtime.quit();
				} else {
					const threadClass = plus.ios.importClass("NSThread"); // 导入了iOS的 NSThread 类。
					const mainThread = plus.ios.invoke(threadClass,
						"mainThread"); // 通过调用 NSThread 类的 mainThread 方法获取主线程对象。
					plus.ios.invoke(mainThread, "exit"); //调用主线程对象的 exit 方法，退出应用程序。
					// ios11
					plus.ios
						.import("UIApplication")
						.sharedApplication()
						.performSelector(
							"exit"
							); //导入 UIApplication 类，调用 sharedApplication 方法获取应用程序对象，然后使用 performSelector 方法调用应用程序对象的 exit 方法,  针对iOS 11及以上版本的退出方式
				}
				//   #endif

				// uni.exit({
				//   success: function () {
				//     console.log("应用程序成功退出");
				//   },
				//   fail: function (err) {
				//     console.log("退出应用程序失败:", err);
				//   },
				// });
				// const pages = getCurrentPages();
				// if (pages.length === 1) {
				//   if (typeof params === 'number') {
				//     history.go(-params);
				//   } else {
				//     history.back();
				//   }
				// } else {
				//   uni.navigateTo({
				//     url: '/',
				//   });
				// }
			},
			// 获取订单支付信息
			payorderinfo: async function() {
				const res = await this.$http.get("/order/inquire");
				// console.log('res', res)
				if (res.data.status == 200) {
					this.orderData = JSON.parse(
						getDecryptString(res.data.data, this.$password())
					);
					// console.log('this.orderData',this.orderData)
					// 订单存在 打开 弹窗 
					if (this.orderData.payStatus == 'pay_ing') {
						this.$refs.popupRef.open();
						// 隐藏的是 获取支付链接
						// this.payurl(res.data.data);
						this.dingdan = res.data.data
					} else {
						return;
					}

				} else {
					// 此订单不存在
					// uni.showToast({
					// 	title: res.data.msg,
					// 	icon: "none",
					// 	duration: 2000,
					// });
				}
			},
			// 获取支付地址
			payurl: async function(data) {
				try {
					const res = await this.$http.post("/order/payOrder", "", {
						params: {
							login: data,
						},
					});
					if (res.data.status == 200) {
						this.submitData = JSON.parse(
							getDecryptString(res.data.data, this.$password())
						);
						console.log(this.submitData, 'this.submitData')

						// 获取支付链接并跳转
						// #ifdef APP-PLUS
						// uni.navigateTo({
						// 	url: this.submitData.payUrl
						// })
						// console.log(this.submitData)
						if (this.submitData.payUrl) {
							// uni.navigateTo uni.redirectTo
							// encodeURIComponent :对 this.submitData.payUrl 进行编码后得到的字符串
							// console.log(this.submitData.payUrl)
							// uni.navigateTo({
							//   url: '/pages/webview/index?url=' + encodeURIComponent('https://www.baidu.com/')  // 要打开的链接地址
							// });
						

							
							uni.navigateTo({
								url: '/pages/webview/index?url=' + encodeURIComponent(this.submitData.payUrl)
							});
						} else {
							uni.showToast({
								title: "Payment order creation failed, please contact customer service",
								icon: "none",
								duration: 2000,
							});
							return;
						}

						// #endif
						// #ifdef H5
						window.location.href = this.submitData.payUrl;
						// #endif
						this.$refs.popupRef.close();

						return;
					}
					// console.log(this.submitData,'this.submitData')
					uni.showToast({
						title: "Payment order creation failed, please contact customer service",
						icon: "none",
						mask: true,
						duration: 2000,
					});
					// 如果未查询到
					// clearInterval(this.timer);
				} catch (err) {
					console.log(err);
				}
			},
			// 获取末项日期
			// paydate: async function () {
			//   try {
			//     const res = await this.$http.get('/order/selectOrder');
			//     // console.log(JSON.parse(getDecryptString(res.data.data, this.$password())), '末项日期');
			//   } catch (err) {
			//     console.log(err);
			//   }
			// },
			// 弹框关闭 - cancel
			popupCancel: function() {
				this.$refs.popupRef.close();
				// clearInterval(this.timer);
			},
			// 弹框关闭 - pay
			popupPay: function() {
				// 打点
				if (!uni.getStorageSync('dadian6')) {
					this.nativePlug = uni.requireNativePlugin("FbKochava")
					if (this.nativePlug != null) {
						this.nativePlug.eventTracking("click_pay", "tel", uni.getStorageSync("phone"))
					}
					uni.setStorageSync('dadian6', '1')
				}

				// 获取支付链接
				this.payurl(this.dingdan);
			},
			// 客服点击事件
			ClickcustomerService: function() {
				// const isCurrent = $_storage.getStorage("ccustomerservice") || 0;
				// if (isCurrent == 2) return;
				// this.current++;
				// this.getUserInfo("click");
				// if (plus.os.name == "Android") {
				//   //安卓
				//   if (
				//     plus.runtime.isApplicationExist({
				//       //查看安卓系统手机有没有下载这款app
				//       pname: "com.baijia.live", //B款app云打包的包名
				//     })
				//   ) {
				//     //安装了app
				//     plus.runtime.openURL(
				//       "whatsapp://send/?phone=" + this.kefutel,
				//       function (res) {
				//         console.log(res);
				//       }
				//     );
				//   } else {
				//     //未安装app
				//     uni.showModal({
				//       title: "WhatsApp is not installed on your phone",
				//       icon: "none",
				//       duration: 2000,
				//     });
				//   }
				// }]
				let tel = uni.getStorageSync('kefutel')
				let name = uni.getStorageSync("kename");
				this.kefu(tel, name);
				// 打点
				if (!uni.getStorageSync('dadian5')) {
					this.nativePlug = uni.requireNativePlugin("FbKochava")
					if (this.nativePlug != null) {
						this.nativePlug.eventTracking("contact_kefu", "tel", uni.getStorageSync("phone"))
					}
					uni.setStorageSync('dadian5', '1')
				}
				// 联系客服统计
				this.$http.get("/user/v1/contactCustomer", {}).then(res => {
				})
				// 用户信息接口  获取  客服电话  客服名称  审核状态      具体查看客服分配逻辑
				this.$http.get("/user/v1/getcurruser", {}).then(res => {
					if (res.data.status == 200) {
						let arr = JSON.parse(getDecryptString(res.data.data, this.$password()));
						// console.log(arr)
						// 然后 调取客服列表
						// 如果当前账号未分配客服  则调用客服列表 进行客服分配
						// loanAmount    loginStatus
						if (arr.linkKefu && arr.loanAmount) {
							// 存在客服 且 存在额度时调用 联系客服自动生成订单”接口
							this.$http.post("/user/v1/order", {}).then(res => {
							})
						} else {
							// 没有客服  直接分配 或者修改客服
							this.kefu(arr.linkKefu, arr.linkName)
						}
					}
				})

				// if (plus.os.name == "Android") { //安卓
				//   if (plus.runtime.isApplicationExist({ //查看安卓系统手机有没有下载这款app
				//     pname: 'com.whatsapp', //B款app云打包的包名 
				//   })) { //安装了app  
				//     plus.runtime.openURL('whatsapp://send/?phone=' + tel,
				//       function (res) {
				//         console.log(res);
				//       });
				//   } else { //未安装app
				//     uni.showModal({
				//       title: 'WhatsApp is not installed on your phone',
				//       icon: 'none',
				//       duration: 2000,
				//     });
				//   }
				// }


				if (this.current == 2) {
					$_storage.setStorage("ccustomerservice", this.current);
				}
			},
			// 调用客服列表
			kefu(tel, name) {
				this.kefutel = tel
				this.$http.get("/baseService/list", {
					params: {
						login: getEncryptString('', this.$password())
					}
				}).then(res => {
					if (res.data.status == 200) {
						let arr = JSON.parse(getDecryptString(res.data.data, this.$password()));
						// arr = arr.filter((el) => el.serviceStatus == '1')
						if (!tel || !name) { //

							// 首次登录 没有分配客服  直接分配
							// 随机数
							let suiji = parseInt(Math.floor(Math.random() * arr.length - 1) + 1)
							this.fenpei(arr[suiji])
						} else {
							let kefuname = arr.filter((el) => el.userName == name)
							let kefutel = arr.filter((el) => el.phone == tel)
							if (kefuname.length == 0) {
								// 若用户的客服名称不在客服列表需要重新随机分配一个在线客服
								let suiji = parseInt(Math.floor(Math.random() * arr.length - 1) + 1)
								this.fenpei(arr[suiji])
								return
							}
							if (kefuname.length > 0 && kefutel.length == 0) {
								// 若用户客服名称在客服列表但客服手机号不同需要更改用户的客服手机号
								this.kuna = kefuname[0].userName;
								this.kutel = kefuname[0].phone
								// 变更给予用户弹窗提示
								this.openpop10()
								// 用户同意后跳转到WhatsApp
								return

							} else {
								if (plus.os.name == "Android") { //安卓
									if (plus.runtime.isApplicationExist({ //查看安卓系统手机有没有下载这款app
											pname: 'com.whatsapp', //B款app云打包的包名 
										})) { //安装了app  
										plus.runtime.openURL('whatsapp://send/?phone=' + this.kefutel,
											function(res) {
												console.log(res);
											});
									} else { //未安装app
										uni.showModal({
											title: 'WhatsApp is not installed on your phone',
											confirmText: "Confirm",
											cancelText: "Cancel", //这块是取消的文字
											icon: 'none',
											duration: 2000,
										});

									}
								}
							}

						}
						// Math.floor(Math.random()*arr.length-1)
						// 随机数
						// let suiji = parseInt(Math.floor(Math.random() * arr.length - 1) + 1)
						// this.fenpei(arr[suiji])
					}
				})
			},
			telkefu(tel) {
				if (plus.os.name == "Android") {
					//安卓
					if (
						plus.runtime.isApplicationExist({
							//查看安卓系统手机有没有下载这款app
							pname: "com.whatsapp", //B款app云打包的包名
						})
					) {
						//安装了app
						plus.runtime.openURL("whatsapp://send/?phone=" + tel, function(res) {
							// console.log(res);
						});
					} else {
						//未安装app
						uni.showModal({
							title: "WhatsApp is not installed on your phone",
							icon: "none",
							confirmText: "Confirm",
							cancelText: "Cancel",
							duration: 2000,
						});
					}
				}
			},
			// 联系客服
			kefus() {
				let tel = uni.getStorageSync("kefutel");
				let name = uni.getStorageSync("kename");
				this.kefu(tel, name)

			},
			// 保存用户信息 分配客服
			fenpei(val, val1, va) {
				let data
				// 若用户客服名称在客服列表但客服手机号不同需要更改用户的客服手机号
				if (va) {
					console.log('0001')
					console.log(this.kutel)
					data = {
						linkKefu: this.kutel, //手机号
						linkName: this.kuna, //客服名字
						accountStatus: uni.getStorageSync('brand') || '' // 机型
					}
				} else {
					if (!val1) {
						data = {
							linkKefu: val.phone, //手机号
							linkName: val.userName, //客服名字
							accountStatus: uni.getStorageSync('brand') || '' // 机型
						}
						console.log('0003')
					} else {
						console.log('0002')

						// 直接分配客服
						data = {
							linkKefu: val1.phone, //手机号
							linkName: val.userName, //客服名字
							accountStatus: uni.getStorageSync('brand') || '' // 机型
						}
					}
					this.kefutel = val.phone
				}
				let datas = getEncryptString(JSON.stringify(data), this.$password())
				this.$http.post("/user/v1/save", '', {
					params: {
						login: datas
					}
				}).then(res => {
					if (res.data.status == 200) {
						// 重新获取用户信息 客服
						this.getUserInfo("click");
						if (plus.os.name == "Android") { //安卓
							if (plus.runtime.isApplicationExist({ //查看安卓系统手机有没有下载这款app
									pname: 'com.whatsapp', //B款app云打包的包名 
								})) { //安装了app  
								plus.runtime.openURL('whatsapp://send/?phone=' + this.kefutel,
									function(res) {
										console.log(res);
									});
							} else { //未安装app
								uni.showModal({
									title: 'WhatsApp is not installed on your phone',
									confirmText: "Confirm",
									cancelText: "Cancel",
									icon: 'none',
									duration: 2000,
								});
							}
						}
					}
				})
			},
			// 关闭更换客服电话号 弹窗
			closesurepop() {
				this.$refs.popup10.close()
			},
			// 打开更换客服手机号 弹窗
			openpop10() {
				this.$refs.popup10.open('center')
			},
			// 同意变更手机号 则跳转 wats app
			sures() {
				this.fenpei('', '', this.kutel);
				this.closesurepop();
				if (plus.os.name == "Android") { //安卓
					if (plus.runtime.isApplicationExist({ //查看安卓系统手机有没有下载这款app
							pname: 'com.whatsapp', //B款app云打包的包名 
						})) { //安装了app  
						plus.runtime.openURL('whatsapp://send/?phone=' + this.kefutel,
							function(res) {
								console.log(res);
							});
					} else { //未安装app
						uni.showModal({
							title: 'WhatsApp is not installed on your phone',
							confirmText: "Confirm",
							cancelText: "Cancel",
							icon: 'none',
							duration: 2000,
						});
					}
				}
			},

			// 点击跳转路由操作
			RouterClick: function(val) {
				const path =
					val == "Loan agreement" ?
					"/pages/contract/contract" :
					"/pages/limit/limit";
				uni.navigateTo({
					url: path,
				});
			},
			//获取系统配置信息
			getSystemInfo: async function() {
				const res = await this.$http.get("/sysconfig/list1");
				if (res.data.status == 200) {
					// console.log(JSON.parse(getDecryptString(res.data.data, this.$password())), 654646);
					this.popupTime = Number(
						JSON.parse(getDecryptString(res.data.data, this.$password())).find(
							(el) => el.sysKey == "支付弹起间隔"
						).sysVal
					);
					uni.setStorageSync("dingtime", this.popupTime);
					// 客服检车时间
					this.timeskefu = JSON.parse(getDecryptString(res.data.data, this.$password())).find(el => el
						.sysKey ==
						"首页客服检测时间").sysVal
					this.banben = JSON.parse(getDecryptString(res.data.data, this.$password())).find(el => el.sysKey ==
						"版本信息").sysVal
					let banbenhao = this.banben.split(',')[0]
					// 版本提示信息  1 不提示 2提示
					this.shouldShowPopup();
					if (this.popshow == true || banbenhao > uni.getStorageSync('banbenhao')) {
						// console.log(12346)
						uni.setStorageSync('banbenhao', banbenhao);
						uni.showToast({
							title: this.banben.split(',')[1],
							icon: "none",
							duration: 2000,
						});
					}
					let dat=JSON.parse(getDecryptString(res.data.data, this.$password()));
					let dats= dat.filter((el) => el.sysKey == "loan_mode")
					if(dats[0].sysVal=='front3_2'){
						this.$Router.replaceAll({
							name: "audithome",
							params: this.types,
						});
					}

				}
			},
			// 版本提示弹窗
			shouldShowPopup() {
				const lastShown = uni.getStorageSync("popupLastShown"); // 从 localStorage 中获取上次弹出提示框的时间
				
				if ((!lastShown || (uni.getStorageSync('phone') == uni.getStorageSync('usernumber')&& !uni.getStorageSync("tan1")))  && this.amount) {
					// 如果还没有弹出过提示框，或者是新用户   则应该弹出
					uni.setStorageSync('popupLastShown', Date.now().toString()); // 存储当前时间到 localStorage 中
					this.popshow = true;
					 uni.setStorageSync("tan1",'1')
				} else {
					const lastShownTime = parseInt(lastShown);
					const now = Date.now();
					const oneDay = 24 * 60 * 60 * 1000; // 一天的毫秒数
					if (Number(now - lastShownTime) >= Number(oneDay)) {
						// console.log(12366)
						// 如果距离上次弹出提示框已经超过一天，则应该弹出
						uni.setStorageSync('popupLastShown', now.toString()); // 存储当前时间到 localStorage 中
						this.popshow = true;
					} else {
						// 否则不应该弹出提示框
						this.popshow = false;
					}
				}
				// console.log(this.popshow,'this.popshow')
			},



			// 获取用户信息
			getUserInfo: async function(type) {
				const res = await this.$http.get("/user/v1/getcurruser");
				// console.log('res', JSON.parse(getDecryptString(res.data.data, this.$password())))

				if (res.data.status == 200) {
					this.currentData = JSON.parse(
						getDecryptString(res.data.data, this.$password())
					);
					this.loaning = this.currentData.orderStatus ? this.currentData.orderStatus : 'LOANING'
					if (this.loaning == 1) {
						this.loaning = 'Loan waiting'
					} else if (this.loaning == 2) {
						this.loaning = 'Loan successful'
					} else if (this.loaning == 3) {
						this.loaning = 'Loan failure'
					}
					// 金额
					this.amount = this.currentData.loanAmount
					if (type == "click") {
						const info = JSON.parse(
							getDecryptString(res.data.data, this.$password())
						);
						this.kefutel = this.currentData.linkKefu;
						this.kename = this.currentData.linkName;
						// console.log(this.kefutel)
						uni.setStorageSync('kefutel', this.kefutel)
						uni.setStorageSync('kename', this.kename)

						// if (info.linkKefu && info.loginStatus) {
						//   // 存在客服 且 存在额度时调用 联系客服自动生成订单”接口
						//   this.$http.get("/user/v1/order", {}).then((res) => {
						//     console.log(res, "满足条件");
						//   });
						// } else {
						//   // 没有客服  直接分配 或者修改客服
						//   this.kefu(info.linkKefu, info.linkName);
						// }
					}
					
				}
			},
			//随机生成 50条数据
			generateRandomString() {
				const firstLetter = String.fromCharCode(Math.floor(Math.random() * 26) + 97); // 随机生成首字母，使用 ASCII 码转换
				const loanAmount = Math.floor(Math.random() * 46 + 5) * 10000; // 随机生成 5 万到 50 万的整万数
				return `${firstLetter}**** took a loan of ${loanAmount} on the platform`;
			},
			generateRandomStrings(count) {
				const result = [];
				for (let i = 0; i < count; i++) {
					const randomString = this.generateRandomString();
					result.push(randomString);
				}
				// return result;
				this.swipers = result
			},
			// onlpop(val) {
			// 	let timer = setInterval(() => {
			// 		if (
			// 			this.orderData.payStatus &&
			// 			this.orderData.description &&
			// 			this.orderData.paydescription
			// 		) {
			// 			if (this.$refs.popupRef) {
			// 				if (this.$refs.popupRef._data.showPopup == false) {
			// 					if (this.orderData.payStatus == "pay_ing") {
			// 						this.$nextTick(() => {
			// 							// this.getSystemInfo();
			// 							this.$refs.popupRef.open();
			// 						});
			// 					}
			// 				}
			// 			} else {
			// 				clearInterval(timer);
			// 			}
			// 		} else {
			// 			clearInterval(timer);
			// 		}
			// 	}, val * 1000);
			// },
			// 支付成功表
			ondingdan() {
				setInterval(async () => {
					const res = await this.$http.get("/order/kochavaOrder1");
					let add = JSON.parse(getDecryptString(res.data.data, this.$password()));
					// 打点
					this.nativePlug = uni.requireNativePlugin("FbKochava");
					if (this.nativePlug != null) {
						this.nativePlug.eventTrackingTwo("pay_success", "tel", uni.getStorageSync("phone"),
							this.amount, 'inr')
					}
					retutn;
				}, 1000 * 60) //
			},
			// 检测客服
			onjianche() {
				if (this.jiance == true && (!uni.getStorageSync('kefutimes') || (Date.parse(new Date()) - uni
						.getStorageSync('kefutimes')) / 1000 > this.timeskefu)) {
					let tel = uni.getStorageSync('kefutel')
					let name = uni.getStorageSync("kename");
					// this.kefu(tel, name);
					uni.setStorageSync('kefutimes', Date.parse(new Date()))
					 console.log('tel',tel)
					this.$http.get("/baseService/list", {
						params: {
							login: getEncryptString('', this.$password())
						}
					}).then(res => {
						if (res.data.status == 200) {
							console.log(name)
							let arr = JSON.parse(getDecryptString(res.data.data, this.$password()));
							let kefuname = arr.filter((el) => el.userName == name)
							let kefutel = arr.filter((el) => el.phone == tel)
							// console.log(arr)
							 console.log(kefuname[0])
							 this.bgname=kefuname[0].userName
							 this.bgtel=kefuname[0].phone
							if (kefuname[0].phone!=tel ) { //kefuname.length == 0 ||kefutel.length == 0
								// 打开弹窗用户同意则更换客服
								this.$refs.popup11.open('center')
								// 若用户的客服名称不在客服列表需要重新随机分配一个在线客服
								// let suiji = parseInt(Math.floor(Math.random() * arr.length - 1) + 1)
								// this.fenpei(arr[suiji])
								// return
							}
							// if (kefuname.length > 0 && kefutel.length == 0) {
							// 	// 若用户客服名称在客服列表但客服手机号不同需要更改用户的客服手机号
							// 	this.kuna = kefuname[0].userName;
							// 	this.kutel = kefuname[0].phone
							// 	// 变更给予用户弹窗提示
							// 	this.openpop10()
							// 	// 用户同意后跳转到WhatsApp
							// 	return

							// }
						}
					})
				}
			},
			// 客服检测  客户同意重新分配客服
			fenpei11(){
				let data = {
					linkKefu: this.kutel, //手机号
					linkName: this.kuna, //客服名字
					accountStatus: uni.getStorageSync('brand') || '' // 机型
				}
				let datas = getEncryptString(JSON.stringify(data), this.$password())
				this.$http.post("/user/v1/save", '', {
					params: {
						login: datas
					}
				}).then(res => {
					if (res.data.status == 200) {
						uni.showToast({
							title: "Change successful",
							icon: "none",
							duration: 2000,
						});
						this.$refs.popup11.close()
						
						uni.setStorageSync('kefutel',this.bgtel)
						 uni.setStorageSync("kename",this.bgname);
					}
				})
			},
			// 关闭 客服检测 弹窗
			closeopen11(){
				this.$refs.popup11.close()
			}
			
		},
		onPullDownRefresh() {
			let that = this;
			setTimeout(function() {
				// that.payorderinfo();
				that.getUserInfo();
				// that.getSystemInfo();
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onLoad() {
			this.isStartTime = true
			// this.payorderinfo();
			// this.paydate();
			this.getUserInfo();
			// this.swipers = msglist();
			// this.getSystemInfo();
			this.generateRandomStrings(50);
		},
		onUnload() {
			uni.setStorageSync('currentPage', '/pages/index/index'); // 保存当前页面到本地存储
			this.isStartTime = false
			clearInterval(this.timer);
		},
		onBackPress() {
			uni.setStorageSync('currentPage', '/pages/index/index'); // 保存当前页面到本地存储
		},
		onHide() {
			clearInterval(this.timer);
		},

		watch: {
			popupTime(val) {
				if (val) {
					this.timer = setInterval(() => {
						this.payorderinfo()
					}, val * 1000)
				} else {
					clearInterval(this.timer);
				}






				// if (val && this.isStartTime) {
				// 	let timer = setInterval(() => {
				// 	  if (
				// 	    this.orderData.payStatus &&
				// 	    this.orderData.description &&
				// 	    this.orderData.paydescription
				// 	  ) {
				// 	    if (this.$refs.popupRef) {
				// 	      if (this.$refs.popupRef._data.showPopup == false) {
				// 	        if (this.orderData.payStatus == "pay_ing") {
				// 	          this.$nextTick(() => {
				// 	            this.getSystemInfo();
				// 	            this.$refs.popupRef.open();
				// 	          });
				// 	        }
				// 	      }
				// 	    } else {
				// 	      clearInterval(timer);
				// 	    }
				// 	  } else {
				// 	    clearInterval(timer);
				// 	  }
				// 	}, val * 1000);
				// }
			},
		},
	};
</script>

<style scoped>
	.index {
		min-height: 100vh;
		padding-bottom: 220rpx;
	}

	.buttontext {
		font-size: 14rpx;
		text-align: center;
		color: rgba(213, 48, 48);
		/* font-size: bold; */
		/* padding: 30rpx 0; */
		margin-top: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.buttontext .buttonimg {
		width: 30rpx;
		height: 30rpx;
		margin-right: 10rpx;
	}

	.popupRef {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.returns {
		width: 100% !important;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 45rpx;
	}

	.returns .pop-img {
		width: 260rpx;
		height: 200rpx;
		margin: 15rpx auto 35rpx;
		display: block;
	}

	.returns .pop-tit {
		text-align: center;
		color: #333;
		font-size: 34rpx;
		font-weight: bold;
	}

	.returns .pop-text {
		text-align: center;
		font-size: 24rpx;
		color: #999;
		line-height: 24rpx;
		margin-top: 10rpx;
	}

	.returns .pop-btn {
		width: 100%;
		display: flex;
		align-items: center;
		column-gap: 50rpx;
		margin-top: 50rpx;
	}

	.tabbar {
		z-index: 1;
	}

	.returns .pop-btn .quit {
		width: 250rpx;
		height: 60rpx;
		line-height: 60rpx;
		color: #4787fd;
		font-size: 30rpx;
	}

	.returns .pop-btn .closes {
		width: 250rpx;
		height: 60rpx;
		line-height: 60rpx;
		background-color: #eee;
		font-size: 30rpx;
	}

	.popup {
		background: #fff;
		padding: 36rpx 68rpx;
		margin: 0 24rpx;
		border-radius: 16rpx;
		box-sizing: border-box;
	}

	.popup .popupTitle {
		display: flex;
		justify-content: center;
		align-items: center;
		position: relative;
	}

	.popup .popupTitle .TitleText {
		font-weight: bold;
		color: #000;
		font-size: 36rpx;
	}

	.popup .popupTitle .popupIcon {
		position: absolute;
		top: -15rpx;
		right: -30rpx;
		font-size: 32rpx;
		color: #000;
	}

	.popup .popupMain {
		margin-top: 40rpx;
	}

	.popup .popupMain .popupText {
		font-size: 28rpx;
		color: #000;
		font-family: revert;
		font-weight: 400;
	}

	.popup .popupBtn {
		margin-top: 40rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.popup .popupBtn .btntext {
		/* padding: 20rpx 50rpx; */
		height: 70rpx;
		width: 220rpx;
		border-radius: 16rpx;
		border: solid 4rpx #999;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.popup .popupBtn .pay {
		margin-left: 60rpx;
		border: none;
		background: rgba(170, 170, 170);
		color: #fff;
	}

	.q_nav {
		padding-top: 88rpx;
		background-color: #d53030;
		padding-left: 36rpx;
		padding-right: 40rpx;
		height: 204rpx;
		display: flex;
		justify-content: space-between;
		box-sizing: border-box;
		align-items: center;
	}

	.q_nav .n_kefu {
		width: 48rpx;
		height: 46rpx;
	}

	.q_nav .n_kefu image {
		width: 100%;
		height: 100%;
	}

	.q_nav .nav_title {
		font-size: 38rpx;
		font-family: "SourceHanSansSC-Regular", "SourceHanSansSC";
		font-weight: 400;
		color: #ffffff;
		line-height: 54rpx;
		letter-spacing: 2rpx;
	}

	.q_nav .n_back {
		width: 22rpx;
		height: 38rpx;
	}

	.launchapp {
		width: 22rpx;
		height: 38rpx;
		border: none;
		background: none;
		background-color: none;
		padding-left: 0;
		padding-right: 0;
		margin-left: 0;
		margin-right: 0;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.launchapp image {
		width: 100%;
		height: 100%;
	}

	.q_nav .n_back image {
		width: 100%;
		height: 100%;
	}

	.swiperbox {
		width: 100%;
		height: 40px !important;
		height: 80rpx !important;
		padding: 0rpx 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background: rgba(241, 241, 241);
	}

	.swiper {
		width: 100%;
		height: 20px !important;
		height: 40rpx !important;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.swiper .swiperItem {
		display: flex;
		align-items: center;
		justify-content: flex-start;
		color: #000;
	}

	.index_header {
		padding-top: 38rpx;
		padding-left: 18rpx;
		padding-right: 18rpx;
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		background-color: #fff;
	}

	.loadingBox {
		width: 100%;
		display: flex;
		justify-content: flex-end;
	}

	.index_header .loaning {
		min-width: 136rpx;
		height: 46rpx;
		border-radius: 40rpx;
		border: 2rpx solid #d53030;
		font-size: 20rpx;
		font-family: "SourceHanSansSC-Medium", "SourceHanSansSC";
		font-weight: 600;
		color: #d53030;
		line-height: 42rpx;
		text-align: center;
		margin-left: 6rpx;
		padding: 0rpx 15rpx;
	}

	.index_header .loan_txt {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-bottom: 16rpx;
	}

	.index_header .loan_txt .loan_title {
		font-size: 40rpx;
		font-family: "SourceHanSansSC-Medium", "SourceHanSansSC";
		font-weight: 600;
		color: #000000;
		line-height: 28rpx;
	}

	.index_header .loan_txt .loan_mony {
		font-size: 66rpx;
		font-family: "SourceHanSansSC-Medium", "SourceHanSansSC";
		font-weight: 600;
		color: #d53030;
		line-height: 96rpx;
	}

	.index_header .loan_txt .loan_aline {
		width: 100%;
		height: 2rpx;
		opacity: 0.12;
		border: 2rpx solid #000000;
		margin-top: 44rpx;
		margin-bottom: 14rpx;
	}

	.index_header .loan_txt .loan_button {
		width: 100%;
		display: flex;
		justify-content: space-between;
		height: 66rpx;
		align-items: center;
		font-size: 32rpx;
		font-family: "SourceHanSansSC-Regular", "SourceHanSansSC";
		font-weight: 400;
		color: #d53030;
		position: relative;
		padding-left: 38rpx;
		padding-right: 54rpx;
	}

	.index_header .loan_txt .loan_button .loan_alines {
		width: 2rpx;
		height: 66rpx;
		border: 2rpx solid #e1e1e1;
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
	}

	.index_min {
		padding-top: 30rpx;
		background-color: #fff;
		width: 100%;
		padding-bottom: 32rpx;
		padding-left: 62rpx;
		padding-right: 76rpx;
		box-sizing: border-box;
		margin-bottom: 48rpx;
	}

	.index_min .min_center {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.index_min .min_center .m_loan {
		width: 100%;
		text-align: left;
		font-size: 40rpx;
		font-family: "SourceHanSansSC-Medium", "SourceHanSansSC";
		font-weight: 600;
		color: #000000;
		line-height: 58rpx;
		display: flex;
		align-items: center;
	}

	.m_loanImage {
		margin-left: 20rpx;
		width: 40rpx;
		height: 40rpx;
	}

	.slot-icon {
		width: 21px;
		height: 21px;
		background-color: #6cd404;
		border-radius: 100px;
		font-size: 12px;
		color: #fff;
		line-height: 21px;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.slot-icons {
		width: 21px;
		height: 21px;
		background-color: #d53030;
		border-radius: 100px;
		font-size: 12px;
		color: #fff;
		line-height: 21px;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.SERVICE {
		width: 702rpx;
		height: 88rpx;
		background: #d53030;
		border-radius: 16rpx;
		margin: auto;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 34rpx;
		font-family: "SourceHanSansSC-Medium", "SourceHanSansSC";
		font-weight: 500;
		color: #ffffff;
		animation: fade 1s linear forwards infinite;
	}

	@keyframes fade {
		0% {
			transform: scale(1);
		}

		25% {
			transform: scale(1.02);
		}

		50% {
			transform: scale(1.05);
		}

		75% {
			transform: scale(1.02);
		}

		100% {
			transform: scale(1);
		}
	}

	.SERVICE image {
		width: 46rpx;
		height: 44rpx;
		margin-right: 44rpx;
	}

	.u-steps /deep/ .u-text .u-text__value.u-text__value--tips {
		font-size: 28rpx !important;
		font-family: "SourceHanSansSC-Regular", "SourceHanSansSC";
		font-weight: 400;
		color: #d53030;
		line-height: 40rpx !important;
		margin-bottom: 18px !important;
	}

	.u-steps /deep/ .u-text .u-text__value.u-text__value--content {
		font-size: 36rpx !important;
		font-family: "SourceHanSansSC-Medium", "SourceHanSansSC";
		font-weight: 500 !important;
		color: #4a3314;
		line-height: 52rpx !important;
	}

	.u-steps /deep/ .u-text__value.u-text__value--main {
		font-size: 36rpx !important;
		font-family: "SourceHanSansSC-Medium", "SourceHanSansSC";
		font-weight: 500 !important;
		color: #4a3314;
		line-height: 52rpx !important;
	}

	.u-steps /deep/ .u-steps-item__line.u-steps-item__line--column {
		background-color: #d53030 !important;
		height: 100% !important;
	}
</style>